<template>
  <div class="userManagement-container">
    <vab-query-form>
      <vab-query-form-left-panel :span="12">
        <el-form :inline="true" :model="queryForm" @submit.native.prevent>
          <el-form-item>
            <el-input v-model.trim="queryForm.name" clearable placeholder="请输入姓名" @clear="queryData"  @keyup.enter.native="queryData" />
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="queryData">查询</el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-left-panel>
    </vab-query-form>
    <el-table v-loading="listLoading" class="table-height" :data="list" :element-loading-text="elementLoadingText">
      <el-table-column label="姓名" prop="name" show-overflow-tooltip />
      <el-table-column label="操作类型" prop="operationType" show-overflow-tooltip />
      <el-table-column label="类型" prop="module" show-overflow-tooltip />
      <el-table-column label="操作时间" min-width="160" prop="updateAt" show-overflow-tooltip>
        <template #default="{ row }">
          {{ parseTime(row.updateAt) }}
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background :current-page="queryForm.pageNo" :layout="layout" :page-size="queryForm.pageSize" :total="total" @current-change="handleCurrentChange" @size-change="handleSizeChange" />
    <edit ref="edit" @fetch-data="fetchData" />
  </div>
</template>

<script>
import { API_logRecordList, API_logRecordDelete } from '@/api/logRecord'
import { parseTime } from '@/utils/index'
export default {
  name: 'LogRecord',
  data() {
    return {
      parseTime,
      list: [],
      listLoading: true,
      layout: 'total, sizes, prev, pager, next, jumper',
      total: 0,
      elementLoadingText: '正在加载...',
      queryForm: {
        pageNo: 1,
        pageSize: 10,
        name:'',
      },
      timeOutID: null,
    }
  },
  created() {
    this.fetchData()
  },
  beforeDestroy() {
    clearTimeout(this.timeOutID)
  },
  methods: {
    handleSizeChange(val) {
      this.queryForm.pageSize = val
      this.fetchData()
    },
    handleCurrentChange(val) {
      this.queryForm.pageNo = val
      this.fetchData()
    },
    queryData() {
      this.queryForm.pageNo = 1
      this.fetchData()
    },
    async fetchData() {
      this.listLoading = true
      const { data } = await API_logRecordList(this.queryForm)
      this.list = data.list
      this.total = data.count
      this.timeOutID = setTimeout(() => {
        this.listLoading = false
      }, 300)
    },
  },
}
</script>
